package com.example.demo.service.Impl;

import com.example.demo.entity.User;
import com.example.demo.entity.UserExample;
import com.example.demo.mapper.UserMapper;
import com.example.demo.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

@Service
public class UserServiceImpl implements UserService {

    @Autowired
    UserMapper userMapper;

    @Override
    public List<User> getUserList() {
        return userMapper.selectByExample(new UserExample());
    }

    @Override
    public User getById(Integer userId) {
        return userMapper.selectByPrimaryKey(userId);
    }

    //添加用户
    @Override
    public int addUser(User user){
        return userMapper.insert(user);
    }

    //删除用户
    @Override
    public int deleteById(Integer userId) {
        return userMapper.deleteByPrimaryKey(userId);
    }

    @Override
    public int updateUserLoginDate(Integer userId, Date date){
        User user = new User();
        user.setUserId(userId);
        user.setUserLoginDate(date);
        return userMapper.updateByPrimaryKeySelective(user);
    }

    @Override
    public int setUserInformation(Integer userId, String name, String introduce, Date birthday){
        User user = new User();
        user.setUserId(userId);
        user.setUserName(name);
        user.setUserIntroduce(introduce);
        user.setUserBirthday(birthday);
        return  userMapper.updateByPrimaryKeySelective(user);
    }

    //忘记密码
    @Override
    public int updatePwd(Integer userId,String userPassword) {
        User user=new User();
        user.setUserId(userId);
        user.setUserPassword(userPassword);
        return userMapper.updateByPrimaryKeySelective(user);
    }


    //绑定邮箱
    @Override
    public int bindEmailAddress(Integer userId,String userMail){
        User user = new User();
        user.setUserId(userId);
        user.setUserMail(userMail);
        return userMapper.updateByPrimaryKeySelective(user);
    }

    //更新手机号
    public int updatePhone(Integer userId,String userPhoneNum){
        User user = new User();
        user.setUserId(userId);
        user.setUserPhoneNum(userPhoneNum);
        return userMapper.updateByPrimaryKeySelective(user);
    }

    //更新邮箱
    public int updateMail(Integer userId,String userMail){
        User user = new User();
        user.setUserId(userId);
        user.setUserMail(userMail);
        return userMapper.updateByPrimaryKeySelective(user);
    }

    @Override
    public int updatePassword(Integer userId, String password) {
        User user = new User();
        user.setUserId(userId);
        user.setUserPassword(password);
        return userMapper.updateByPrimaryKeySelective(user);
    }

}

